//
//  LQProgressView.swift
//  weiboLQ
//
//  Created by 半缘君 on 15/12/20.
//  Copyright © 2015年 banyuanjun.cn. All rights reserved.
//

import UIKit

class LQProgressImageView: UIImageView {
    private lazy var progressView:LQProgressView = LQProgressView()
    var progress:CGFloat = 0 {
        didSet {
            progressView.progress = progress
        }
    }
    init () {
        super.init(frame: CGRectZero)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   private func setupUI () {
        addSubview(progressView)
    progressView.backgroundColor = UIColor.clearColor()
    progressView.snp_makeConstraints { (make) -> Void in
        make.edges.equalTo(self.snp_edges)
    }
    
    }
    
}

class LQProgressView: UIView {
    var progress:CGFloat = 0 {
        didSet {
            setNeedsDisplay()
        }
    }
    override func drawRect(rect: CGRect) {
        
        let centerPoint:CGPoint = CGPoint(x: rect.width * 0.5, y: rect.height * 0.5)
        
        let r:CGFloat = min(bounds.height, bounds.width) / 2
        
        let start:CGFloat = CGFloat (-M_PI_2)
        
        let end:CGFloat = start + progress * CGFloat (2 * M_PI)
        let path = UIBezierPath(arcCenter: centerPoint, radius: r, startAngle: start, endAngle: end, clockwise: true)
        path.addLineToPoint(centerPoint)
        UIColor(white: 1.0, alpha: 0.2).setFill()
//        UIColor.redColor().setFill()
        path.fill()
        
    }
}
